package smallDemend.literalCombat;

import java.util.Random;

public class Role {
    private String name;
    private int blood = 100;

    public Role() {
    }

    public Role(String name) {
        this.name = name;
    }

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }
    public void setBlood(int blood) {
        this.blood = blood;
    }
    //攻击方法
    public void attack(Role role) {
        //生成随机血量
        Random r = new Random();
        int harm = r.nextInt(20) + 1;
        int blo = (role.blood - harm);
        int bio1 = blo < 0 ? 0 : blo;

        role.setBlood(bio1);
        if (bio1 == 0) {
            System.out.println(role.getName() + "被K.O!!!!");
            System.exit(0);
        } else {
            System.out.println(this.getName() + "打了" +
                    role.getName() + "一下," +
                    "造成了" + harm + "的血量伤害，"
                    + role.getName() + "还剩下"
                    + bio1 + "的血量");
        }
    }
}
